package t1jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ResourceBundle;

public class JDBCUtil {

	private static ResourceBundle rb=ResourceBundle.getBundle("t1jdbc.jdbc");
	private static String username = rb.getString("username");
	private static String password = rb.getString("password");
	private static String url="jdbc:mysql://127.0.0.1:3306/"+rb.getString("ku")+"?"+rb.getString("url");
	private static String driver=rb.getString("driver");

	static {
		try {
			Class.forName(driver);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

	public static Connection getConnection() throws ClassNotFoundException, SQLException {
		return DriverManager.getConnection(url, username, password);
	}

	public static void close(Connection conn, Statement st, ResultSet rs) throws SQLException {
		if (conn != null) {
			conn.close();
			conn = null;
		}
		if (st != null) {
			st.close();
			st = null;
		}
		if (rs != null) {
			rs.close();
			rs = null;
		}
	}

	public static void close(Connection conn, Statement st) throws SQLException {
		close(conn, st, null);
	}
	

}
